package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.statistics.ExportCountRespVO;
import com.tbit.uqbike.object.pojo.vo.UpKeepLogQueryReqVO;
import com.tbit.uqbike.object.pojo.vo.UpKeepLogReqVO;
import com.tbit.uqbike.object.pojo.vo.UpKeepLogRespVO;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.common.entity.view.PageResult;
import com.tbit.uqbike.service.business.UpKeepLogService;
import com.tbit.uqbike.webmanager.util.excel.ExcelUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yao
 * @since 2025/1/23 10:05
 */
@RestController
@RequestMapping("/upKeepLog")
public class UpKeepLogController {

    @Resource
    private UpKeepLogService upKeepLogService;

    @RequestMapping("/getPage")
    public JsonResult getPage(UpKeepLogQueryReqVO reqVO) {

        PageResult<UpKeepLogRespVO> page = upKeepLogService.getPage(reqVO);

        return JsonResult.ok(page);
    }

    @RequestMapping("/getDateList")
    public JsonResult getDateList(UpKeepLogQueryReqVO reqVO) {

        List<UpKeepLogRespVO> list = upKeepLogService.getDateList(reqVO);

        return JsonResult.ok(list);
    }

    @RequestMapping("/getCountPage")
    public JsonResult getCountPage(UpKeepLogQueryReqVO reqVO) {

        PageResult<UpKeepLogRespVO> page = upKeepLogService.getCountPage(reqVO);

        return JsonResult.ok(page);
    }

    @RequestMapping("/export")
    public JsonResult export(UpKeepLogQueryReqVO reqVO) {
        reqVO.setRowCount(-1);
        PageResult<UpKeepLogRespVO> page = upKeepLogService.getPage(reqVO);
        return JsonResult.ok(new ExcelUtil<>(UpKeepLogRespVO.class).exportExcel(page.getList(), "保养统计").getData());
    }

    @RequestMapping("/exportCount")
    public JsonResult exportCount(UpKeepLogQueryReqVO reqVO) {
        reqVO.setRowCount(-1);
        PageResult<UpKeepLogRespVO> page = upKeepLogService.getCountPage(reqVO);
        PageResult<ExportCountRespVO> exportPage = PageResult.convertPage(page, ExportCountRespVO.class);
        return JsonResult.ok(new ExcelUtil<>(ExportCountRespVO.class).exportExcel(exportPage.getList(), "保养记录").getData());
    }

    @RequestMapping("/get")
    public JsonResult getById(Integer id) {

        UpKeepLogRespVO upKeepLog = upKeepLogService.getById(id);

        return JsonResult.ok(upKeepLog);
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody UpKeepLogReqVO reqVO) {

        upKeepLogService.update(reqVO);

        return JsonResult.ok();
    }

}
